'/
' Fetherquest Online
' 
' =========================================================================
' 
' This program is free software: you can redistribute it and/or modify
' it under the terms of the GNU General Public License as published by
' the Free Software Foundation, either version 3 of the License, or
' (at your option) any later version.
' 
' This program is distributed in the hope that it will be useful,
' but WITHOUT ANY WARRANTY; without even the implied warranty of
' MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
' GNU General Public License for more details.
' 
' You should have received a copy of the GNU General Public License
' along with this program.  If not, see <http://www.gnu.org/licenses/>.
'/

'// All methods that start with E_* are methods that are used as events that the graphical user interface
'// invokes. Other methods are just methods used by these events in some way or another.
type EventManager extends Base

	'// -------------------------------------------------------------------------------------------------------------
	'// Event:
	'//   Null
	'// Descr:
	'//   Nothing.
	'// -------------------------------------------------------------------------------------------------------------
	method E_Null()
	
		'sSoundManager.playSound("menu_fx", "clickButton");
		'sSoundManager.update();
	
	end method
	
	'// -------------------------------------------------------------------------------------------------------------
	'// Event:
	'//   Show exit game query
	'// Descr:
	'//   Shows the window that asks whether or not the user is sure to exit the game.
	'// -------------------------------------------------------------------------------------------------------------
	method E_ShowExitGame()
	
		'// Play sound.
		'sSoundManager.playSound("menu_fx", "clickButton");
		'sSoundManager.update();
		
		'// This layer.
		local layer:GUI_Layer = g_activeSurface.getLayer("exitGame_layer");
		layer.setVisibility(true);
		layer.activate();
		
		'// Main layer.
		layer = g_activeSurface.getLayer("main_layer");
		layer.deactivate();
	
	end method
	
	'// -------------------------------------------------------------------------------------------------------------
	'// Event:
	'//   Hide exit game query
	'// Descr:
	'//   Hides the window that asks whether or not the user is sure to exit the game.
	'// -------------------------------------------------------------------------------------------------------------
	method E_HideExitGame()
	
		'// Play sound.
		'sSoundManager.playSound("menu_fx", "clickButton");
		'sSoundManager.update();
		
		'// This layer.
		local layer:GUI_Layer = g_activeSurface.getLayer("exitGame_layer");
		layer.setVisibility(false);
		layer.deactivate();
		
		'// Main layer.
		layer = g_activeSurface.getLayer("main_layer");
		layer.activate();
	
	end method
	
	'// -------------------------------------------------------------------------------------------------------------
	'// Event:
	'//   Exit game
	'// Descr:
	'//   Exits to Windows.
	'// -------------------------------------------------------------------------------------------------------------
	method E_ExitGame()
	
		'// Play sound.
		'sSoundManager.playSound("menu_fx", "clickButton");
		'sSoundManager.update();
		
		'// Perform action.
		g_activeSurface.getLayer("exitGame_layer").deactivate();
		sMaster.m_stopEvent = true;
	
	end method
	
	'// -------------------------------------------------------------------------------------------------------------
	'// Event:
	'//   Login
	'// Descr:
	'//   Login to the master server with the specified account information.
	'// -------------------------------------------------------------------------------------------------------------
	method E_LogIn()
	
		'// Play sound.
		'sSoundManager.playSound("menu_fx", "clickButton");
		'sSoundManager.update();
		
		local layer:GUI_Layer = sGUI.getSurface("main_menu").getLayer("main_layer");
		local nameForm:GUI_Form = layer.getForm("form_account_name");
		local passwForm:GUI_Form = layer.getForm("form_account_passw");
		
		if (nameForm.getInput() and passwForm.getInput()) ..
			sNetworkManager.m_masterPeer.loginToMaster(nameForm.getInput(), passwForm.getInput());
	
	end method
	
	'// -------------------------------------------------------------------------------------------------------------
	'// Event:
	'//   Close okay dialog
	'// Descr:
	'//   Close the okay dialog from the main menu layer.
	'// -------------------------------------------------------------------------------------------------------------
	method E_MainMenu_CloseOkayDialog()
	
		'// Play sound.
		'sSoundManager.playSound("menu_fx", "clickButton");
		'sSoundManager.update();
		
		'// This layer.
		local layer:GUI_Layer = g_activeSurface.getLayer("okaydialog_layer");
		layer.setVisibility(false);
		layer.deactivate();
		
		'// Main layer.
		layer = g_activeSurface.getLayer("main_layer");
		layer.activate();
	
	end method

end type

global sEventManager:EventManager = new EventManager;
